﻿using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace K9Nano.FileStorage;

public interface IFileStorage
{
    /// <summary>
    /// 存储文件
    /// </summary>
    /// <param name="stream">文件流</param>
    /// <param name="leaveOpen">是否关闭文件流</param>
    /// <param name="cancellation"></param>
    /// <returns>文件相对访问路径</returns>
    Task<string> SaveAsync(Stream stream, string ext, bool leaveOpen = false, CancellationToken cancellation = default);

    /// <summary>
    /// 打开文件流以便读取
    /// </summary>
    /// <param name="uri">文件相对访问路径</param>
    /// <param name="cancellation"></param>
    /// <returns></returns>
    Task<Stream> OpenReadAsync(string uri, CancellationToken cancellation = default);

    /// <summary>
    /// 获取临时文件路径
    /// </summary>
    /// <param name="ext">文件扩展名</param>
    /// <returns>绝对路径</returns>
    string GetTmpFile(string ext);
}
